<template>
  <view class="container">
    <uni-list>
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'person-filled'}" title="昵称" :rightText="userNickName" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'phone-filled'}" title="手机号码" :rightText="userPhone" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'email-filled'}" title="邮箱" :rightText="userEmail" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'auth-filled'}" title="岗位" :rightText="postGroup" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'staff-filled'}" title="角色" :rightText="roleGroup" />
      <uni-list-item showExtraIcon="true" :extraIcon="{type: 'calendar-filled'}" title="创建日期" :rightText="userCreateTime" />
    </uni-list>
  </view>
</template>

<script>
  import { getUserProfile } from "@/api/system/user"

  export default {
    data() {
      return {
        user: {},
        roleGroup: "",
        postGroup: ""
      }
    },
    computed: {
      userNickName() {
        return this.user && this.user.nickName ? this.user.nickName : '未设置'
      },
      userPhone() {
        return this.user && this.user.phonenumber ? this.user.phonenumber : '未设置'
      },
      userEmail() {
        return this.user && this.user.email ? this.user.email : '未设置'
      },
      userCreateTime() {
        return this.user && this.user.createTime ? this.user.createTime : '未设置'
      }
    },
    async onLoad() {
      await this.getUser()
      if (!this.user || !this.user.nickName) {
        this.$tab.reLaunch('/pages/login')
      }
    },
    methods: {
      async getUser() {
        try {
          const response = await getUserProfile()
          console.log('获取用户信息响应:', response)
          
          this.user = response.data || {}
          this.roleGroup = response.roleGroup || ''
          this.postGroup = response.postGroup || ''
          
          console.log('用户信息:', this.user)
          
          // 检查用户信息是否完整
          if (!this.user || !this.user.nickName) {
            console.warn('用户信息不完整，跳转到登录页')
            this.$tab.reLaunch('/pages/login')
          }
        } catch (error) {
          console.error('获取用户信息失败:', error)
          this.$tab.reLaunch('/pages/login')
        }
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #ffffff;
  }
</style>
